//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<InputReflection.h>
///	@path	~/src/appear/xwin/
///	@date	2007/11/08
///	@desc	Reflects inputs to engine's event center.

#pragma once

#include "xeres.h"

#include "appear/app/input_handler.h"

#include "engine/xcore/CInputEvent.h"
#include "engine/xcore/xeres_engine.h"

namespace xeres {

	/*!
		\class	InputReflection
		\brief	Reflects inputs to engine's event center.
	*/
	class InputReflection : public InputHandler
	{
	public:

		/// \ctor
		InputReflection( void );

		/// \dtor
		virtual ~InputReflection( void );

	//@ interface

		/*!
			\brief		Process key input message.
		*/
		virtual HandleInput OnKeyInput( const KeyInput& input );

		/*!
			\brief		Process mouse input message.
		*/
		virtual HandleInput OnMouseInput( const MouseInput& input );

	//@ local

		/*!
			\brief		Create event object & register callback.
		*/
		bool ConnectEngine( Engine& engine );

		/*!
			\brief		Dispatch input messages to engine.
						This call should be insert to input stage.
		*/
		void DispatchInput( void );

	private:

	//@ data

		// key event
		Ref< CInputEvent >		m_keyEvent;

		// mouse event
		Ref< CInputEvent >		m_mouseEvent;

		// input message queue
		struct _InputMessage
		{
#define	MAXSIZE( A , B )		sizeof(A) > sizeof(B) ? sizeof(A) : sizeof(B)
			uchar buffer[ MAXSIZE( KeyInput , MouseInput ) ];
#undef MAXSIZE
		};

		// queue
		std::deque< _InputMessage >		m_messageQueue;
	};

} // namespace xeres
